#include <bits/stdc++.h>
using namespace std;
int t,n,m,L,V,d,v,a,cs=0;
bool f=1;
int read();
void write(int x);
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    t=read();
    for(int i=1;i<=t;i++){
        n=read();
        m=read();
        L=read();
        V=read();
        cs=0;
        f=1;
        for(int j=1;j<=n;j++){
             d=read(),v=read(),a=read();
             if(a!=0){
                f=0;
             }
             if(v>V) cs++;
        }
        for(int j=1;j<=m;j++){
            read();
        }
        if(f==1){

            write(cs);
            putchar(' ');
            if(cs) write(m-1);
            else write(m);
            putchar('\n');
        }
    }

    return 0;
}

int read(){
    int x,y=1;char c;
    while((c=getchar())>'9'||c<'0') if(c=='-') y=-1;
    x=(c^48);
    while((c=getchar())>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48);
    return x*y;
}

void write(int x){
    if(x<0) x=-x,putchar('-');
    if(x>9) write(x/10);
    putchar(x%10+48);

}
